package o;

import android.content.Context;
import android.graphics.Rect;
import android.text.TextUtils;
import android.view.Display;
import android.view.WindowManager;
import com.huawei.android.os.SystemPropertiesEx;

public class HwDisplayRegionUtils {
    private static int ˊ(float f) {
        return (int) (((double) f) * (1.0d - (1.0d / Math.sqrt(2.0d))));
    }

    private static int getUserRotation(Context context) {
        if (context != null) {
            WindowManager windowManager = (WindowManager) context.getSystemService("window");
            if (windowManager != null) {
                Display defaultDisplay = windowManager.getDefaultDisplay();
                if (defaultDisplay != null) {
                    return defaultDisplay.getRotation();
                }
            }
        }
        return 0;
    }

    public static Rect configRoundCorner(Context context) {
        if (context != null && azc.ˎ().ॱ() >= 21) {
            Object obj = SystemPropertiesEx.get("hw.config.roundcorner", "");
            ayv.ˎ.ˎ("HwDisplayRegionUtils", "this device config round corner value: " + obj);
            if (!TextUtils.isEmpty(obj)) {
                String[] split = obj.split(",");
                if (split.length == 4) {
                    float floatValue = Float.valueOf(split[0]).floatValue();
                    float floatValue2 = Float.valueOf(split[1]).floatValue();
                    float floatValue3 = Float.valueOf(split[2]).floatValue();
                    float floatValue4 = Float.valueOf(split[3]).floatValue();
                    int ˊ = ˊ(floatValue);
                    int ˊ2 = ˊ(floatValue2);
                    int ˊ3 = ˊ(floatValue3);
                    int ˊ4 = ˊ(floatValue4);
                    Rect rect = new Rect();
                    if (ˊ > ˊ2) {
                        rect.top = ˊ;
                    } else {
                        rect.top = ˊ2;
                    }
                    if (ˊ > ˊ3) {
                        rect.left = ˊ;
                    } else {
                        rect.left = ˊ3;
                    }
                    if (ˊ2 > ˊ4) {
                        rect.right = ˊ2;
                    } else {
                        rect.right = ˊ4;
                    }
                    if (ˊ3 > ˊ4) {
                        rect.bottom = ˊ3;
                    } else {
                        rect.bottom = ˊ4;
                    }
                    ˊ = rect.left;
                    ˊ2 = rect.right;
                    ˊ3 = rect.top;
                    ˊ4 = rect.bottom;
                    if (3 == getUserRotation(context)) {
                        ayv.ˎ.ˎ("HwDisplayRegionUtils", "ROTATION_270");
                        rect = ॱ(rect, ˊ4, ˊ, ˊ3, ˊ2);
                    } else if (1 == getUserRotation(context)) {
                        ayv.ˎ.ˎ("HwDisplayRegionUtils", "ROTATION_90");
                        rect = ॱ(rect, ˊ3, ˊ2, ˊ4, ˊ);
                    }
                    ayv.ˎ.ˎ("HwDisplayRegionUtils", "roundRect=" + rect);
                    UserRationRectCache.ˏ().setRationRect(rect);
                    return rect;
                }
            }
        }
        return null;
    }

    private static Rect ॱ(Rect rect, int i, int i2, int i3, int i4) {
        if (rect != null) {
            rect.left = i;
            rect.top = i2;
            rect.right = i3;
            rect.bottom = i4;
        }
        return rect;
    }

    public static void ˎ() {
        UserRationRectCache.ˏ().destroy();
    }
}
